//防抖函数
export function deBounce(fn: Function, time = 300, isImmediately = false) {
  let timer: NodeJS.Timeout | null = null;

  return (...args: any) => {
    if (timer) clearTimeout(timer);

    if (isImmediately) {
      fn.apply(this, args);

      setTimeout(() => {
        timer = null;
      }, time);
    } else {
      timer = setTimeout(() => {
        fn.apply(this, args);
      }, time);
    }
  };
}
